<?php


//************************************
//cookie
//CURLOPT_COOKIE
//CURLOPT_COOKIEFILE
//CURLOPT_COOKIEJAR
//CURLOPT_CUSTOMREQUEST  //GET,POST,CONNECT,DELETE
//CURLOPT_POSTFIELDS  //To post a file, prepend a filename with @ and use the full path
//CURLOPT_REFERER
//
//CURLOPT_URL
//CURLOPT_USERAGENT
//CURLOPT_BUFFERSIZE
//CURLOPT_CONNECTTIMEOUT
//CURLOPT_CONNECTTIMEOUT_MS
//CURLOPT_TIMEOUT
//
//CURLOPT_SSL_VERIFYHOST
//
//
//CURLOPT_UPLOAD
//CURLOPT_PUT
//CURLOPT_POST
//CURLOPT_NOBODY
//CURLOPT_HEADER //true: input header in output

function cURL($url, $header=NULL, $cookie=NULL, $p=NULL)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, $header);
    curl_setopt($ch, CURLOPT_NOBODY, $header);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_COOKIE, $cookie);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    if ($p) {
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $p);
    }
    $result = curl_exec($ch);
    if ($result) {
        return $result;
    } else {
        return curl_error($ch);
    }
    curl_close($ch);
}

echo ($a = cURL('http://facebook.com', TRUE, NULL, 'abc'));
//echo cURL('http://localhost/test/curl/login/end.php', NULL, NULL, NULL);
preg_match('%Set-Cookie: ([^;]+);%',$a,$b);
echo '<pre>';print_r($b);echo '</pre>';

die();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost/test/curl/login/end.php?a=1');


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost/test/curl/login/end.php');

$result = curl_exec($ch);

echo $result;

curl_close($ch);